import Axios from "axios";
import NProgress from "nprogress";
import { Message } from "element-ui";

export default function(config) {
  const itf = Axios.create({
    baseURL: "/api",
    // 发送请求携带cookie
    withCredentials: true,
    timeout: 10000,
  });
  itf.interceptors.response.use((result) => result.data);

  return new Promise((resolve, reject) => {
    itf(config)
      .then((result) => {
        NProgress.done();
        resolve(result);
      })
      .catch((result) => {
        NProgress.done();
        Message.error("网络异常");
        resolve(null);
      });
  });
}
